import 'package:flutter/material.dart';
import 'package:flutter_scaffold/flutter_scaffold.dart';

/// 多个文本选中拖动
/// @data:2025/7/21
/// @author:zhibo.huang
class TextDropDemoPage extends StatefulWidget {
  const TextDropDemoPage({super.key});

  @override
  State<TextDropDemoPage> createState() => _TextDropDemoPageState();
}

class _TextDropDemoPageState extends State<TextDropDemoPage> {
  var dx = 0.0;
  var dy = 0.0;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: Text("text drop")),
      body: Container(
        color: Colors.amberAccent,
        width: double.infinity,
        height: 200.h,
        child: LayoutBuilder(
          builder: (context,constra){
            Log.i(constra.biggest);
            return  GestureDetector(
              onPanStart: (details) {
                Log.i("====按下:${details.toString()}");
              },
              onPanUpdate: (details) {
                Log.i(
                  "====移动:${dx += details.delta.dx},${dy += details.delta.dy}",
                );
                dx = dx.clamp(0, constra.maxWidth- 80.w);
                dy = dy.clamp(0, constra.maxHeight- 40.w);
                setState(() {});
              },
              onPanEnd: (details) {
                Log.i("====抬起:${details.toString()}");
              },
              child: Stack(
                children: [
                  Positioned(
                    left: dx,
                    top: dy,
                    child: DecoratedBox(
                      decoration: BoxDecoration(
                        border: Border.all(color: Colors.red),
                      ),
                      child: Container(
                        decoration: BoxDecoration(),
                        clipBehavior: Clip.hardEdge,
                        child: Text(
                          "黄智波",
                          style: TextStyle(fontSize: 26.sp),
                          maxLines: 1,
                        ),
                      ),
                    ),
                  ),

                  Positioned(
                    left: 5.w,
                    top: 55.w,
                    child: DecoratedBox(
                      decoration: BoxDecoration(
                        border: Border.all(color: Colors.red),
                      ),
                      child: Container(
                        decoration: BoxDecoration(),
                        clipBehavior: Clip.hardEdge,
                        child: Text(
                          "黄智波",
                          style: TextStyle(fontSize: 26.sp),
                          maxLines: 1,
                        ),
                      ),
                    ),
                  ),
                ],
              ),
            );
          },
        ),
      ),
    );
  }
}
